Allow to set a global hook function thats called whenever a link button is
authorMatthias Clasen <mclasen@redhat.com>
Sat, 28 Jan 2006 06:20:30 +0000 (06:20 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Sat, 28 Jan 2006 06:20:30 +0000 (06:20 +0000)
2006-01-28  Matthias Clasen  <mclasen@redhat.com>

* gtk/gtk.symbols:
* gtk/gtklinkbutton.h:
* gtk/gtklinkbutton.c: Allow to set a global hook function
thats called whenever a link button is clicked.

ChangeLog
ChangeLog.pre-2-10
docs/reference/ChangeLog
docs/reference/gtk/gtk-sections.txt
gtk/gtk.symbols
gtk/gtklinkbutton.c
gtk/gtklinkbutton.h

index 55cab24d3b912b17721c74295e141200941946d8..d0b21d746f60847f8fd3b194ddaac467f14faa0c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2006-01-28  Matthias Clasen  <mclasen@redhat.com>
 
+       * gtk/gtk.symbols: 
+       * gtk/gtklinkbutton.h: 
+       * gtk/gtklinkbutton.c: Allow to set a global hook function
+       thats called whenever a link button is clicked.
+
        More work on GtkAssistant by Carlos Garnacho:
        
        * demos/gtk-demo/Makefile.am: 
index 55cab24d3b912b17721c74295e141200941946d8..d0b21d746f60847f8fd3b194ddaac467f14faa0c 100644 (file)
@@ -1,5 +1,10 @@
 2006-01-28  Matthias Clasen  <mclasen@redhat.com>
 
+       * gtk/gtk.symbols: 
+       * gtk/gtklinkbutton.h: 
+       * gtk/gtklinkbutton.c: Allow to set a global hook function
+       thats called whenever a link button is clicked.
+
        More work on GtkAssistant by Carlos Garnacho:
        
        * demos/gtk-demo/Makefile.am: 
index 3654f95c5105b6f5c8512f53e9befc288dedefdc..0474f0f78e0bce55808b2a19400d16f65480aa12 100644 (file)
@@ -1,5 +1,7 @@
 2006-01-28  Matthias Clasen  <mclasen@redhat.com>
 
+       * gtk/gtk-sections.txt: Add gtk_link_button_set_uri_hook
+
        * gtk/gtk-docs.sgml: 
        * gtk/migrating-GtkAssistant.sgml: Add a migration guide
        GnomeDruid --> GtkAssistant.  (Carlos Garnacho)
index c5e6d888913578d11a2ecf51550b370211b78b22..9d95693d4745ea2bd53e4c91988fea51dfd3e241 100644 (file)
@@ -2077,6 +2077,7 @@ gtk_link_button_new
 gtk_link_button_new_with_label
 gtk_link_button_get_uri
 gtk_link_button_set_uri
+gtk_link_button_set_uri_hook
 
 <SUBSECTION Standard>
 GTK_TYPE_LINK_BUTTON
index 987dfab75dcda68de9d9a02fd200d87dd05ca8a1..764c76c57e320b5b4da3b811d0785c66fa9ee882 100644 (file)
@@ -2001,6 +2001,7 @@ gtk_link_button_new
 gtk_link_button_new_with_label
 gtk_link_button_get_uri
 gtk_link_button_set_uri
+gtk_link_button_set_uri_hook
 #endif
 #endif
 
index 8bae769dc1e141476d216ff6652cee7e62b74cb9..c0e2ea038cc11e938ceece9c13c14de352000069 100644 (file)
@@ -102,6 +102,10 @@ static const GtkTargetEntry link_drop_types[] = {
 static GdkColor default_link_color = { 0, 0, 0, 0xeeee };
 static GdkColor default_visited_link_color = { 0, 0x5555, 0x1a1a, 0x8b8b };
 
+static GtkLinkButtonUriFunc uri_func = NULL;
+static gpointer uri_func_data = NULL;
+static GDestroyNotify uri_func_destroy = NULL;
+
 G_DEFINE_TYPE (GtkLinkButton, gtk_link_button, GTK_TYPE_BUTTON);
 
 static void
@@ -436,6 +440,9 @@ gtk_link_button_clicked (GtkButton *button)
 {
   GtkLinkButton *link_button = GTK_LINK_BUTTON (button);
 
+  if (uri_func)
+    (* uri_func) (button, link_button->priv->uri, uri_func_data);
+
   link_button->priv->visited = TRUE;
 
   set_link_color (link_button);
@@ -615,5 +622,38 @@ gtk_link_button_get_uri (GtkLinkButton *link_button)
   return link_button->priv->uri;
 }
 
+/**
+ * gtk_link_button_set_uri_hook:
+ * @func: a function called each time a #GtkLinkButton is clicked, or %NULL
+ * @data: user data to be passed to @func, or %NULL
+ * @destroy: a #GDestroyNotify that gets called when @data is no longer needed, or %NULL
+ *
+ * Sets @func as the function that should be invoked every time a user clicks
+ * a #GtkLinkButton. This function is called before every callback registered
+ * for the "clicked" signal.
+ *
+ * Return value: the previously set hook function.
+ *
+ * Since: 2.10
+ */
+GtkLinkButtonUriFunc
+gtk_link_button_set_uri_hook (GtkLinkButtonUriFunc func,
+                             gpointer             data,
+                             GDestroyNotify       destroy)
+{
+  GtkLinkButtonUriFunc old_uri_func;
+
+  if (uri_func_destroy)
+    (* uri_func_destroy) (uri_func_data);
+
+  old_uri_func = uri_func;
+
+  uri_func = func;
+  uri_func_data = data;
+  uri_func_destroy = destroy;
+
+  return old_uri_func;
+}
+
 #define __GTK_LINK_BUTTON_C__
 #include "gtkaliasdef.c"
index 25affc7e71f9ce804062153329e7f6ab4c44e7e9..92b48512e0a3ff64c6653a028349509ae87631c1 100644 (file)
@@ -41,6 +41,10 @@ typedef struct _GtkLinkButton                GtkLinkButton;
 typedef struct _GtkLinkButtonClass     GtkLinkButtonClass;
 typedef struct _GtkLinkButtonPrivate   GtkLinkButtonPrivate;
 
+typedef void (*GtkLinkButtonUriFunc) (GtkLinkButton *button,
+                                     const gchar   *link,
+                                     gpointer       user_data);
+
 struct _GtkLinkButton
 {
   GtkButton parent_instance;
@@ -68,6 +72,10 @@ G_CONST_RETURN gchar *gtk_link_button_get_uri           (GtkLinkButton *link_but
 void                  gtk_link_button_set_uri           (GtkLinkButton *link_button,
                                                         const gchar   *uri);
 
+GtkLinkButtonUriFunc  gtk_link_button_set_uri_hook      (GtkLinkButtonUriFunc func,
+                                                        gpointer             data,
+                                                        GDestroyNotify       destroy);
+
 G_END_DECLS
 
 #endif /* __GTK_LINK_BUTTON_H__ */